package code.bolin.ufw.common;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author bolin
 * @create 2023-05
 * @desc
 */
public class LogUtil {

    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static void log(String msg) {
        StackTraceElement[] stackTraceElements = new Throwable().getStackTrace();
        StackTraceElement stackTraceElement = stackTraceElements[0];
        if (stackTraceElements.length > 1) {
            stackTraceElement = stackTraceElements[1];
        }
        // date class method file line
        System.out.println(String.format("%s-%s#%s(%s:%s): %s", sdf.format(new Date()), stackTraceElement.getClassName(), stackTraceElement.getMethodName(), stackTraceElement.getFileName(), stackTraceElement.getLineNumber(), msg));
    }

    public static void main(String[] args) {
        log("test");
    }
}
